<template>
  <div class="login_container">
    <vue-particles color="#409EFF"
                   :particleOpacity="0.7"
                   :particlesNumber="60"
                   shapeType="circle"
                   :particleSize="6"
                   linesColor="#409EFF"
                   :linesWidth="1"
                   :lineLinked="true"
                   :lineOpacity="0.4"
                   :linesDistance="150"
                   :moveSpeed="3"
                   :hoverEffect="true"
                   hoverMode="grab"
                   :clickEffect="true"
                   clickMode="push">
    </vue-particles>
    <div class="login_box">
      <el-row>
        <div class="avatar_box">
          <img src="../assets/xuecheng.png"
               alt="">
        </div>
      </el-row>
      <el-form ref="loginFormRef"
               :model="loginForm"
               class="login_form"
               :rules="loginFormRules">
        <el-form-item prop="username">
          <i class="el-icon-user"></i>
          <el-input v-model="loginForm.username"
                    clearable></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <i class="el-icon-lock"></i>
          <el-input placeholder="请输入密码"
                    v-model="loginForm.password"
                    show-password></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary"
                     class="login-btns"
                     @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
  data() {
    return {
      loginForm: {
        username: 'admin',
        password: 'admin',
        verifycode: '1234'
      },
      loginFormRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 3, max: 12, message: '长度在 3 到 12 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    ...mapMutations(['setToken']),
    login() {     
        this.$refs.loginFormRef.validate(async (valid) => {
            if (!valid) {
              return false
            }
            if( this.loginForm.username=='admin'&& this.loginForm.password=='admin'){
                this.setToken('jdfkkfkkf')
                this.$message({
                  duration:1000,
                  message:'登录成功，香宝',
                  type:'success'        
                })
                this.$router.push('/kanban')
            }else{
                this.$message({
                    duration:1000,
                    message:'登录失败，香宝',
                    type:'error'        
                  })
            }             
          })
    }
  }
}
</script>

<style lang="less" scoped>
.login_container {
  background: url('../assets/login.1f741d77.png') no-repeat;
  background-size: cover;
  height: 100%;
}

.login_box {
  width: 450px;
  height: 350px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

  .avatar_box {
    position: absolute;
    top: 40px;
    height: 28px;
    img {
      position: absolute;
      left: 175px;
      height: 100%;
    }
  }
}

.login_form {
  position: absolute;
  bottom: 40px;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
  .el-form-item {
    margin-bottom: 25px;
    i {
      position: absolute;
      top: 13px;
      left: 11px;
      z-index: 10;
    }
  }
}
/deep/.el-input__inner {
  padding-left: 30px !important;
}
// .btns {
//   display: flex;
//   justify-content: flex-end;
// }
.login-btns {
  width: 100%;
  background: linear-gradient(90deg, #3b99f8, #10d3d9);
}
#particles-js {
  width: 100%;
  height: calc(100% - 100px);
  position: absolute; //设置absolute,其他DIV设置为relative，这样这个例子效果就作为背景
}
</style>
